package main

import "io/ioutil"
import "os"
import "fmt"
import "strconv"
import "trigger.googlecode.com/hg/lib/uri"
import "trigger.googlecode.com/hg/lib/rdf"
import "trigger.googlecode.com/hg/lib/turtle"
import "strings"

type sink struct {
    prefixes map[string]string
    // G rdf.Graph
}

var bcount = 1000

func (h sink) ExpandPrefix(qName string) string {
    i := strings.IndexAny( qName, ":" )
    p := qName[:i+1]
    e := h.prefixes[p] + qName[i+1:]
    return "<" + e + ">" 
}

func (h sink) BNode() rdf.Node {
    bcount += 1
    return rdf.AsURI("bn:" + strconv.Itoa(bcount))
    }

func (h sink) SetPrefix( qname string, def uri.Type ) {
    fmt.Println( "prefix", qname, def )
    h.prefixes[qname] = (string(def))[1:len(string(def))-1]
}

func (h sink) Add( s, p, o rdf.Node ) {
    fmt.Println( "triple: ", s, p, o )
}

func main() {
    h := sink{make(map[string]string)} //, NewMemGraph()}
    bytes, _ := ioutil.ReadAll( os.Stdin )
    all := string(bytes)
    turtle.Main( h, all )
}
